//
//  FinishLine.m
//  MessangerSkeleton
//
//  Created by User-23 on 4/27/14.
//  Copyright (c) 2014 IOTrainingCamp. All rights reserved.
//

#import "FinishLine.h"
#import "cocos2d.h"
#import "Configuration.h"

@interface FinishLine ()

@property GameObjectType* type;
@end


@implementation FinishLine

- (instancetype)init
{
    self = [super initWithSpriteFrame:[CCSpriteFrame frameWithImageNamed:@"FinishLine.png"]];
    if (self) {
        
        self.type = kFinishLine;
        
        //TODO: should be loaded from a plist and this should be separate method common for all sprites
//        int num = 24;
//        CGPoint* finishLine = malloc(sizeof(CGPoint)*num);
//
//        finishLine[0] = ccp(23.0f, 139.7f);
//        finishLine[1] = ccp(-5.3f, 148.6f);
//        finishLine[2] = ccp(-24.1f, 147.4f);
//        finishLine[3] = ccp(-35.7f, 136.4f);
//        finishLine[4] = ccp(-63.3f, 109.2f);
//        finishLine[5] = ccp(-96.3f, 77.7f);
//        finishLine[6] = ccp(-107.4f, 72.7f);
//        finishLine[7] = ccp(-121.2f, 75.4f);
//        finishLine[8] = ccp(-144.4f, 80.2f);
//        finishLine[9] = ccp(-143.4f, 68.7f);
//        finishLine[10] = ccp(-130.5f, 38.2f);
//        finishLine[11] = ccp(-91.1f, -64.1f);
//        finishLine[12] = ccp(-78.6f, -71.2f);
//        finishLine[13] = ccp(-57.4f, -78.1f);
//        finishLine[14] = ccp(-35.4f, -73.7f);
//        finishLine[15] = ccp(-19.9f, -60.1f);
//        finishLine[16] = ccp(37.0f, -4.8f);
//        finishLine[17] = ccp(47.7f, 0.8f);
//        finishLine[18] = ccp(75.1f, -9.8f);
//        finishLine[19] = ccp(128.0f, -142.8f);
//        finishLine[20] = ccp(137.2f, -145.9f);
//        finishLine[21] = ccp(145.3f, -148.4f);
//        finishLine[22] = ccp(31.4f, 141.2f);
//        finishLine[23] = ccp(20.9f, 141.1f);
//        
//        CGPoint offset = ccp(155, 150);
//        
//        for(int i=0; i< num; i++)
//        {
//            finishLine[i] = ccp(finishLine[i].x + offset.x, finishLine[i].y + offset.y);
//        }
        
        
//        self.physicsBody = [CCPhysicsBody bodyWithPolygonFromPoints:finishLine count:num cornerRadius:20];
        self.physicsBody = [CCPhysicsBody bodyWithRect:CGRectMake(0, 0, 100, 800) cornerRadius:20];
        
//        free(finishLine);
        self.scale = 0.25;
        self.physicsBody.sensor = YES;
        self.physicsBody.collisionType = @"finishLine";
    }
    return self;
}

-(void)update:(CCTime)delta
{
    if(self.position.x + self.boundingBox.size.width < 0)
        [self removeFromParentAndCleanup:YES];
}

@end
